/*     */ package org.jeecgframework.p3.cg.factory;
/*     */ 
/*     */ import freemarker.template.Configuration;
/*     */ import freemarker.template.DefaultObjectWrapper;
/*     */ import java.io.File;
/*     */ import java.io.PrintStream;
/*     */ import java.net.URL;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ import org.jeecgframework.p3.cg.ColumnData;
/*     */ import org.jeecgframework.p3.cg.CreateBean;
/*     */ import org.jeecgframework.p3.cg.def.CodeResourceUtil;
/*     */ import org.jeecgframework.p3.cg.def.FreemarkerEngine;
/*     */ import org.jeecgframework.p3.cg.pojo.onetomany.CodeParamEntity;
/*     */ import org.jeecgframework.p3.cg.pojo.onetomany.SubTableEntity;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CodeGenerateFactoryOneToMany
/*     */ {
/*  36 */   private static final Log log = LogFactory.getLog(CodeGenerateFactoryOneToMany.class);
/*  37 */   private static String url = CodeResourceUtil.URL;
/*  38 */   private static String username = CodeResourceUtil.USERNAME;
/*  39 */   private static String passWord = CodeResourceUtil.PASSWORD;
/*  40 */   private static Configuration cfg = new Configuration();
/*  41 */   private static Map<String, Object> root = new HashMap();
/*  42 */   private static CreateBean createBean = new CreateBean();
/*  43 */   private static String pathSrc = "";
/*     */   
/*     */   static {
/*  46 */     pathSrc = CodeResourceUtil.getConfigInfo("path_src");
/*  47 */     String source_root_package = CodeResourceUtil.getConfigInfo("source_root_package");
/*  48 */     pathSrc = pathSrc + File.separator + source_root_package.replace(".", File.separator); }
/*  49 */   private static String author = CodeResourceUtil.getConfigInfo("author");
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static void oneToManyCreate(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/*  60 */       createBean.setMysqlInfo(url, username, passWord);
/*  61 */       SimpleDateFormat dateformat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 E ");
/*  62 */       String nowDate = dateformat.format(new Date());
/*  63 */       System.out.println("时间:" + nowDate);
/*  64 */       root.put("author", author);
/*  65 */       root.put("nowDate", nowDate);
/*  66 */       String templateBasePath = getClassPath() + CodeResourceUtil.getConfigInfo("templatepath_ftl") + "/onetomany";
/*  67 */       cfg.setDirectoryForTemplateLoading(new File(templateBasePath));
/*  68 */       cfg.setObjectWrapper(new DefaultObjectWrapper());
/*     */       
/*  70 */       createEntity(codeParamEntityIn, subTabParamIn);
/*     */       
/*  72 */       createDao(codeParamEntityIn, subTabParamIn);
/*     */       
/*  74 */       createDaoImpl(codeParamEntityIn, subTabParamIn);
/*     */       
/*  76 */       createSqlMap(codeParamEntityIn, subTabParamIn);
/*     */       
/*  78 */       createService(codeParamEntityIn, subTabParamIn);
/*     */       
/*  80 */       createServiceImpl(codeParamEntityIn, subTabParamIn);
/*     */       
/*  82 */       createController(codeParamEntityIn, subTabParamIn);
/*     */     }
/*     */     catch (Exception e1) {
/*  85 */       e1.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createController(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/*  91 */     initControllerParam(codeParamEntityIn, subTabParamIn);
/*  92 */     String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/*     */     
/*  94 */     String className = codeParamEntityIn.getEntityName();
/*  95 */     String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/*  96 */     String projectName = codeParamEntityIn.getProjectName();
/*  97 */     String bussiPackage = codeParamEntityIn.getEntityPackage();
/*  98 */     basePackage = basePackage + "." + projectName;
/*  99 */     if (StringUtils.isNotEmpty(bussiPackage)) {
/* 100 */       basePackage = basePackage + "." + bussiPackage;
/*     */     }
/*     */     
/* 103 */     String pagePackage = basePackage + ".page";
/* 104 */     String pagePath = pagePackage.replace(".", "\\") + "\\" + className + "Page.java";
/* 105 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageClass.ftl", pathSrc, pagePath);
/*     */     
/* 107 */     String controllerPackage = basePackage + ".web";
/* 108 */     String controllerPath = controllerPackage.replace(".", "\\") + "\\" + className + "Controller.java";
/* 109 */     FreemarkerEngine.createFileByFTL(cfg, root, "controllerClass.ftl", pathSrc, controllerPath);
/*     */     
/* 111 */     String pageVmPackage = "content." + projectName;
/* 112 */     if (StringUtils.isNotEmpty(bussiPackage)) {
/* 113 */       pageVmPackage = pageVmPackage + "." + bussiPackage;
/*     */     }
/* 115 */     String pageIndexPath = pageVmPackage.replace(".", "\\") + "\\" + lowerName + "-list.vm";
/* 116 */     String pageAddPath = pageVmPackage.replace(".", "\\") + "\\" + lowerName + "-add.vm";
/* 117 */     String pageAddJsPath = pageVmPackage.replace(".", "\\") + "\\" + lowerName + "-add.js";
/* 118 */     String pageEditPath = pageVmPackage.replace(".", "\\") + "\\" + lowerName + "-edit.vm";
/* 119 */     String pageDetailPath = pageVmPackage.replace(".", "\\") + "\\" + lowerName + "-detail.vm";
/* 120 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageIndex.ftl", pathSrc.replace("java", "resources"), pageIndexPath);
/* 121 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageAdd.ftl", pathSrc.replace("java", "resources"), pageAddPath);
/* 122 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageAddJs.ftl", pathSrc.replace("java", "resources"), pageAddJsPath);
/* 123 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageDetail.ftl", pathSrc.replace("java", "resources"), pageDetailPath);
/* 124 */     FreemarkerEngine.createFileByFTL(cfg, root, "pageEdit.ftl", pathSrc.replace("java", "resources"), pageEditPath);
/*     */   }
/*     */   
/*     */   private static void initControllerParam(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 129 */     initControllerMainParam(codeParamEntityIn);
/*     */     
/* 131 */     initControllerSubParam(codeParamEntityIn.getProjectName(), subTabParamIn);
/*     */   }
/*     */   
/*     */   private static void initControllerMainParam(CodeParamEntity codeParamEntityIn) {
/*     */     try {
/* 136 */       String tableName = codeParamEntityIn.getTableName();
/* 137 */       String className = codeParamEntityIn.getEntityName();
/* 138 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 139 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 140 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 141 */       String projectName = codeParamEntityIn.getProjectName();
/* 142 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 143 */       basePackage = basePackage + "." + projectName;
/* 144 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 145 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 147 */       String domainPackage = basePackage + ".entity";
/* 148 */       String servicePackage = basePackage + ".service";
/* 149 */       String pagePackage = basePackage + ".page";
/* 150 */       String pageVmPackage = "content." + projectName;
/* 151 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 152 */         pageVmPackage = pageVmPackage + "." + bussiPackage;
/*     */       }
/* 154 */       String pageAddJsPath = pageVmPackage.replace(".", "/") + "/" + lowerName + "-add.js";
/* 155 */       String controllerPackage = basePackage + ".web";
/* 156 */       root.put("className", className);
/* 157 */       root.put("codeName", codeName);
/* 158 */       root.put("projectName", projectName);
/* 159 */       root.put("tableName", tableName);
/* 160 */       root.put("domainPackage", domainPackage);
/* 161 */       root.put("lowerName", lowerName);
/* 162 */       root.put("bussPackage", bussiPackage);
/* 163 */       root.put("servicePackage", servicePackage);
/* 164 */       root.put("pagePackage", pagePackage);
/* 165 */       root.put("pageAddJsPath", pageAddJsPath);
/* 166 */       root.put("controllerPackage", controllerPackage);
/* 167 */       root.put("mainEntity", codeParamEntityIn);
/* 168 */       List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 169 */       root.put("columnDatas", columnDatas);
/*     */     } catch (Exception e) {
/* 171 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void initControllerSubParam(String projectName, List<SubTableEntity> subTabParamIn)
/*     */   {
/*     */     try {
/* 178 */       for (SubTableEntity sub : subTabParamIn) {
/* 179 */         Map<String, Object> paramData = new HashMap();
/* 180 */         String tableName = sub.getTableName();
/* 181 */         String className = sub.getEntityName();
/* 182 */         String codeName = sub.getFtlDescription();
/* 183 */         String bussiPackage = sub.getEntityPackage();
/* 184 */         String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 185 */         basePackage = basePackage + "." + projectName;
/* 186 */         if (StringUtils.isNotEmpty(bussiPackage)) {
/* 187 */           basePackage = basePackage + "." + bussiPackage;
/*     */         }
/* 189 */         String domainPackage = basePackage + ".entity";
/* 190 */         String daoPackage = basePackage + ".dao";
/* 191 */         String servicePackage = basePackage + ".service";
/* 192 */         String serviceImplPackage = basePackage + ".service.impl";
/* 193 */         String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 194 */         paramData.put("className", className);
/* 195 */         paramData.put("codeName", codeName);
/* 196 */         paramData.put("tableName", tableName);
/* 197 */         paramData.put("domainPackage", domainPackage);
/* 198 */         paramData.put("lowerName", lowerName);
/* 199 */         paramData.put("daoPackage", daoPackage);
/* 200 */         paramData.put("servicePackage", servicePackage);
/* 201 */         paramData.put("serviceImplPackage", serviceImplPackage);
/*     */         
/* 203 */         String foreignKeyTable = sub.getForeignKey().toUpperCase();
/* 204 */         String foreignKeyUpper = createBean.getTablesNameToClassName(foreignKeyTable);
/* 205 */         paramData.put("foreignKeyTable", foreignKeyTable);
/* 206 */         paramData.put("foreignKeyUpper", foreignKeyUpper);
/* 207 */         String foreignKey = foreignKeyUpper.substring(0, 1).toLowerCase() + foreignKeyUpper.substring(1, foreignKeyUpper.length());
/* 208 */         paramData.put("foreignKey", foreignKey);
/*     */         
/* 210 */         String mainForeignKeyTable = sub.getMainForeignKey().toUpperCase();
/* 211 */         String mainForeignKeyUpper = createBean.getTablesNameToClassName(mainForeignKeyTable);
/* 212 */         paramData.put("mainForeignKeyTable", mainForeignKeyTable);
/* 213 */         paramData.put("mainForeignKeyUpper", mainForeignKeyUpper);
/* 214 */         String mainForeignKey = mainForeignKeyUpper.substring(0, 1).toLowerCase() + mainForeignKeyUpper.substring(1, mainForeignKeyUpper.length());
/* 215 */         paramData.put("mainForeignKey", mainForeignKey);
/*     */         
/* 217 */         List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 218 */         paramData.put("columnDatas", columnDatas);
/* 219 */         sub.setParamData(paramData);
/*     */       }
/* 221 */       root.put("subEntityList", subTabParamIn);
/*     */     } catch (Exception e) {
/* 223 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createServiceImpl(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 229 */     createServiceImplMain(codeParamEntityIn);
/*     */     
/* 231 */     for (SubTableEntity sub : subTabParamIn) {
/* 232 */       createServiceImplSub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createServiceImplMain(CodeParamEntity codeParamEntityIn) {
/*     */     try {
/* 238 */       String tableName = codeParamEntityIn.getTableName();
/* 239 */       String className = codeParamEntityIn.getEntityName();
/* 240 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 241 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 242 */       String projectName = codeParamEntityIn.getProjectName();
/* 243 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 244 */       basePackage = basePackage + "." + projectName;
/* 245 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 246 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 248 */       String domainPackage = basePackage + ".entity";
/* 249 */       String daoPackage = basePackage + ".dao";
/* 250 */       String servicePackage = basePackage + ".service";
/* 251 */       String serviceImplPackage = basePackage + ".service.impl";
/* 252 */       String serviceImplPath = serviceImplPackage.replace(".", "\\") + "\\" + className + "ServiceImpl.java";
/* 253 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 254 */       root.put("className", className);
/* 255 */       root.put("codeName", codeName);
/* 256 */       root.put("tableName", tableName);
/* 257 */       root.put("domainPackage", domainPackage);
/* 258 */       root.put("lowerName", lowerName);
/* 259 */       root.put("daoPackage", daoPackage);
/* 260 */       root.put("servicePackage", servicePackage);
/* 261 */       root.put("serviceImplPackage", serviceImplPackage);
/* 262 */       FreemarkerEngine.createFileByFTL(cfg, root, "serviceImplMainClass.ftl", pathSrc, serviceImplPath);
/*     */     }
/*     */     catch (Exception e) {
/* 265 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createServiceImplSub(String projectName, SubTableEntity subTabParamIn) {
/*     */     try {
/* 271 */       String tableName = subTabParamIn.getTableName();
/* 272 */       String className = subTabParamIn.getEntityName();
/* 273 */       String codeName = subTabParamIn.getFtlDescription();
/* 274 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 276 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 277 */       basePackage = basePackage + "." + projectName;
/* 278 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 279 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 281 */       String domainPackage = basePackage + ".entity";
/* 282 */       String daoPackage = basePackage + ".dao";
/* 283 */       String servicePackage = basePackage + ".service";
/* 284 */       String serviceImplPackage = basePackage + ".service.impl";
/* 285 */       String serviceImplPath = serviceImplPackage.replace(".", "\\") + "\\" + className + "ServiceImpl.java";
/* 286 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 287 */       root.put("className", className);
/* 288 */       root.put("codeName", codeName);
/* 289 */       root.put("tableName", tableName);
/* 290 */       root.put("domainPackage", domainPackage);
/* 291 */       root.put("lowerName", lowerName);
/* 292 */       root.put("daoPackage", daoPackage);
/* 293 */       root.put("servicePackage", servicePackage);
/* 294 */       root.put("serviceImplPackage", serviceImplPackage);
/*     */       
/* 296 */       String foreignKeyTable = subTabParamIn.getForeignKey().toUpperCase();
/* 297 */       String foreignKeyUpper = createBean.getTablesNameToClassName(foreignKeyTable);
/* 298 */       root.put("foreignKeyTable", foreignKeyTable);
/* 299 */       root.put("foreignKeyUpper", foreignKeyUpper);
/* 300 */       String foreignKey = foreignKeyUpper.substring(0, 1).toLowerCase() + foreignKeyUpper.substring(1, foreignKeyUpper.length());
/* 301 */       root.put("foreignKey", foreignKey);
/* 302 */       FreemarkerEngine.createFileByFTL(cfg, root, "serviceImplSubClass.ftl", pathSrc, serviceImplPath);
/*     */     }
/*     */     catch (Exception e) {
/* 305 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createService(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 311 */     createServiceMain(codeParamEntityIn);
/*     */     
/* 313 */     for (SubTableEntity sub : subTabParamIn) {
/* 314 */       createServiceSub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createServiceMain(CodeParamEntity codeParamEntityIn)
/*     */   {
/*     */     try
/*     */     {
/* 322 */       String tableName = codeParamEntityIn.getTableName();
/* 323 */       String className = codeParamEntityIn.getEntityName();
/* 324 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 325 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 326 */       String projectName = codeParamEntityIn.getProjectName();
/* 327 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 328 */       basePackage = basePackage + "." + projectName;
/* 329 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 330 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 332 */       String domainPackage = basePackage + ".entity";
/* 333 */       String daoPackage = basePackage + ".dao";
/* 334 */       String servicePackage = basePackage + ".service";
/* 335 */       String servicePath = servicePackage.replace(".", "\\") + "\\" + className + "Service.java";
/* 336 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 337 */       root.put("className", className);
/* 338 */       root.put("codeName", codeName);
/* 339 */       root.put("tableName", tableName);
/* 340 */       root.put("domainPackage", domainPackage);
/* 341 */       root.put("lowerName", lowerName);
/* 342 */       root.put("daoPackage", daoPackage);
/* 343 */       root.put("servicePackage", servicePackage);
/* 344 */       FreemarkerEngine.createFileByFTL(cfg, root, "serviceMainClass.ftl", pathSrc, servicePath);
/*     */     }
/*     */     catch (Exception e) {
/* 347 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createServiceSub(String projectName, SubTableEntity subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/* 355 */       String tableName = subTabParamIn.getTableName();
/* 356 */       String className = subTabParamIn.getEntityName();
/* 357 */       String codeName = subTabParamIn.getFtlDescription();
/* 358 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 360 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 361 */       basePackage = basePackage + "." + projectName;
/* 362 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 363 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 365 */       String domainPackage = basePackage + ".entity";
/* 366 */       String daoPackage = basePackage + ".dao";
/* 367 */       String servicePackage = basePackage + ".service";
/* 368 */       String servicePath = servicePackage.replace(".", "\\") + "\\" + className + "Service.java";
/* 369 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 370 */       root.put("className", className);
/* 371 */       root.put("codeName", codeName);
/* 372 */       root.put("tableName", tableName);
/* 373 */       root.put("domainPackage", domainPackage);
/* 374 */       root.put("lowerName", lowerName);
/* 375 */       root.put("daoPackage", daoPackage);
/* 376 */       root.put("servicePackage", servicePackage);
/*     */       
/* 378 */       String foreignKeyTable = subTabParamIn.getForeignKey().toUpperCase();
/* 379 */       String foreignKeyUpper = createBean.getTablesNameToClassName(foreignKeyTable);
/* 380 */       root.put("foreignKeyTable", foreignKeyTable);
/* 381 */       root.put("foreignKeyUpper", foreignKeyUpper);
/* 382 */       String foreignKey = foreignKeyUpper.substring(0, 1).toLowerCase() + foreignKeyUpper.substring(1, foreignKeyUpper.length());
/* 383 */       root.put("foreignKey", foreignKey);
/* 384 */       FreemarkerEngine.createFileByFTL(cfg, root, "serviceSubClass.ftl", pathSrc, servicePath);
/*     */     }
/*     */     catch (Exception e) {
/* 387 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createSqlMap(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 393 */     createSqlMapMain(codeParamEntityIn);
/*     */     
/* 395 */     for (SubTableEntity sub : subTabParamIn) {
/* 396 */       createSqlMapSub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createSqlMapMain(CodeParamEntity codeParamEntityIn)
/*     */   {
/*     */     try
/*     */     {
/* 404 */       String tableName = codeParamEntityIn.getTableName();
/* 405 */       String className = codeParamEntityIn.getEntityName();
/* 406 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 407 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 408 */       String projectName = codeParamEntityIn.getProjectName();
/* 409 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 410 */       basePackage = basePackage + "." + projectName;
/* 411 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 412 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 414 */       String sqlmapPackage = basePackage + ".sqlmap";
/* 415 */       String sqlmapPath = sqlmapPackage.replace(".", "\\") + "\\" + className + "Entity.xml";
/*     */       
/* 417 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 418 */       root.put("className", className);
/* 419 */       root.put("codeName", codeName);
/* 420 */       root.put("tableName", tableName);
/* 421 */       root.put("lowerName", lowerName);
/*     */       
/* 423 */       List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 424 */       root.put("columnDatas", columnDatas);
/* 425 */       String tablesAsName = createBean.getTablesASName(tableName);
/* 426 */       root.put("tablesAsName", tablesAsName);
/*     */       
/*     */ 
/* 429 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoMainSqlmap.ftl", pathSrc, sqlmapPath);
/*     */     }
/*     */     catch (Exception e) {
/* 432 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createSqlMapSub(String projectName, SubTableEntity subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/* 440 */       String tableName = subTabParamIn.getTableName();
/* 441 */       String className = subTabParamIn.getEntityName();
/* 442 */       String codeName = subTabParamIn.getFtlDescription();
/* 443 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 445 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 446 */       basePackage = basePackage + "." + projectName;
/* 447 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 448 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 450 */       String sqlmapPackage = basePackage + ".sqlmap";
/* 451 */       String sqlmapPath = sqlmapPackage.replace(".", "\\") + "\\" + className + "Entity.xml";
/*     */       
/* 453 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 454 */       root.put("className", className);
/* 455 */       root.put("codeName", codeName);
/* 456 */       root.put("tableName", tableName);
/* 457 */       root.put("lowerName", lowerName);
/*     */       
/* 459 */       List<ColumnData> columnDatas = createBean.getColumnDatas(tableName);
/* 460 */       root.put("columnDatas", columnDatas);
/* 461 */       String tablesAsName = createBean.getTablesASName(tableName);
/* 462 */       root.put("tablesAsName", tablesAsName);
/*     */       
/* 464 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoSubSqlmap.ftl", pathSrc, sqlmapPath);
/*     */     }
/*     */     catch (Exception e) {
/* 467 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDaoImpl(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 473 */     createDaoImplMain(codeParamEntityIn);
/*     */     
/* 475 */     for (SubTableEntity sub : subTabParamIn) {
/* 476 */       createDaoImplSub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDaoImplMain(CodeParamEntity codeParamEntityIn)
/*     */   {
/*     */     try
/*     */     {
/* 484 */       String tableName = codeParamEntityIn.getTableName();
/* 485 */       String className = codeParamEntityIn.getEntityName();
/* 486 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 487 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 488 */       String projectName = codeParamEntityIn.getProjectName();
/* 489 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 490 */       basePackage = basePackage + "." + projectName;
/* 491 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 492 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 494 */       String domainPackage = basePackage + ".entity";
/* 495 */       String daoPackage = basePackage + ".dao";
/* 496 */       String daoImplPackage = basePackage + ".dao.impl";
/* 497 */       String daoImplPath = daoImplPackage.replace(".", "\\") + "\\" + className + "DaoImpl.java";
/* 498 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 499 */       root.put("className", className);
/* 500 */       root.put("codeName", codeName);
/* 501 */       root.put("tableName", tableName);
/* 502 */       root.put("domainPackage", domainPackage);
/* 503 */       root.put("lowerName", lowerName);
/* 504 */       root.put("daoPackage", daoPackage);
/* 505 */       root.put("daoImplPackage", daoImplPackage);
/* 506 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoImplMainClass.ftl", pathSrc, daoImplPath);
/*     */     }
/*     */     catch (Exception e) {
/* 509 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDaoImplSub(String projectName, SubTableEntity subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/* 517 */       String tableName = subTabParamIn.getTableName();
/* 518 */       String className = subTabParamIn.getEntityName();
/* 519 */       String codeName = subTabParamIn.getFtlDescription();
/* 520 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 522 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 523 */       basePackage = basePackage + "." + projectName;
/* 524 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 525 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 527 */       String domainPackage = basePackage + ".entity";
/* 528 */       String daoPackage = basePackage + ".dao";
/* 529 */       String daoImplPackage = basePackage + ".dao.impl";
/* 530 */       String daoImplPath = daoImplPackage.replace(".", "\\") + "\\" + className + "DaoImpl.java";
/* 531 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 532 */       root.put("className", className);
/* 533 */       root.put("codeName", codeName);
/* 534 */       root.put("tableName", tableName);
/* 535 */       root.put("domainPackage", domainPackage);
/* 536 */       root.put("lowerName", lowerName);
/* 537 */       root.put("daoPackage", daoPackage);
/* 538 */       root.put("daoImplPackage", daoImplPackage);
/*     */       
/* 540 */       String foreignKeyTable = subTabParamIn.getForeignKey().toUpperCase();
/* 541 */       String foreignKeyUpper = createBean.getTablesNameToClassName(foreignKeyTable);
/* 542 */       root.put("foreignKeyTable", foreignKeyTable);
/* 543 */       root.put("foreignKeyUpper", foreignKeyUpper);
/* 544 */       String foreignKey = foreignKeyUpper.substring(0, 1).toLowerCase() + foreignKeyUpper.substring(1, foreignKeyUpper.length());
/* 545 */       root.put("foreignKey", foreignKey);
/* 546 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoImplSubClass.ftl", pathSrc, daoImplPath);
/*     */     }
/*     */     catch (Exception e) {
/* 549 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDao(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 555 */     createDaoMain(codeParamEntityIn);
/*     */     
/* 557 */     for (SubTableEntity sub : subTabParamIn) {
/* 558 */       createDaoSub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDaoMain(CodeParamEntity codeParamEntityIn)
/*     */   {
/*     */     try
/*     */     {
/* 566 */       String tableName = codeParamEntityIn.getTableName();
/* 567 */       String className = codeParamEntityIn.getEntityName();
/* 568 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 569 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 570 */       String projectName = codeParamEntityIn.getProjectName();
/* 571 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 572 */       basePackage = basePackage + "." + projectName;
/* 573 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 574 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 576 */       String domainPackage = basePackage + ".entity";
/* 577 */       String daoPackage = basePackage + ".dao";
/* 578 */       String daoPath = daoPackage.replace(".", "\\") + "\\" + className + "Dao.java";
/* 579 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 580 */       root.put("className", className);
/* 581 */       root.put("codeName", codeName);
/* 582 */       root.put("tableName", tableName);
/* 583 */       root.put("domainPackage", domainPackage);
/* 584 */       root.put("lowerName", lowerName);
/* 585 */       root.put("daoPackage", daoPackage);
/* 586 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoMainClass.ftl", pathSrc, daoPath);
/*     */     }
/*     */     catch (Exception e) {
/* 589 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createDaoSub(String projectName, SubTableEntity subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/* 597 */       String tableName = subTabParamIn.getTableName();
/* 598 */       String className = subTabParamIn.getEntityName();
/* 599 */       String codeName = subTabParamIn.getFtlDescription();
/* 600 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 602 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 603 */       basePackage = basePackage + "." + projectName;
/* 604 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 605 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 607 */       String domainPackage = basePackage + ".entity";
/* 608 */       String daoPackage = basePackage + ".dao";
/* 609 */       String daoPath = daoPackage.replace(".", "\\") + "\\" + className + "Dao.java";
/* 610 */       String lowerName = className.substring(0, 1).toLowerCase() + className.substring(1, className.length());
/* 611 */       root.put("className", className);
/* 612 */       root.put("codeName", codeName);
/* 613 */       root.put("tableName", tableName);
/* 614 */       root.put("domainPackage", domainPackage);
/* 615 */       root.put("lowerName", lowerName);
/* 616 */       root.put("daoPackage", daoPackage);
/*     */       
/* 618 */       String foreignKeyTable = subTabParamIn.getForeignKey().toUpperCase();
/* 619 */       String foreignKeyUpper = createBean.getTablesNameToClassName(foreignKeyTable);
/* 620 */       root.put("foreignKeyTable", foreignKeyTable);
/* 621 */       root.put("foreignKeyUpper", foreignKeyUpper);
/* 622 */       String foreignKey = foreignKeyUpper.substring(0, 1).toLowerCase() + foreignKeyUpper.substring(1, foreignKeyUpper.length());
/* 623 */       root.put("foreignKey", foreignKey);
/* 624 */       FreemarkerEngine.createFileByFTL(cfg, root, "daoSubClass.ftl", pathSrc, daoPath);
/*     */     }
/*     */     catch (Exception e) {
/* 627 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createEntity(CodeParamEntity codeParamEntityIn, List<SubTableEntity> subTabParamIn)
/*     */   {
/* 633 */     createEntityMain(codeParamEntityIn);
/*     */     
/* 635 */     for (SubTableEntity sub : subTabParamIn) {
/* 636 */       createEntitySub(codeParamEntityIn.getProjectName(), sub);
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createEntityMain(CodeParamEntity codeParamEntityIn)
/*     */   {
/*     */     try
/*     */     {
/* 644 */       String tableName = codeParamEntityIn.getTableName();
/* 645 */       String className = codeParamEntityIn.getEntityName();
/* 646 */       String codeName = codeParamEntityIn.getFtlDescription();
/* 647 */       String bussiPackage = codeParamEntityIn.getEntityPackage();
/* 648 */       String projectName = codeParamEntityIn.getProjectName();
/* 649 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 650 */       basePackage = basePackage + "." + projectName;
/* 651 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 652 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 654 */       String domainPackage = basePackage + ".entity";
/* 655 */       String domainPath = domainPackage.replace(".", "\\") + "\\" + className + "Entity.java";
/* 656 */       root.put("className", className);
/* 657 */       root.put("codeName", codeName);
/* 658 */       root.put("tableName", tableName);
/* 659 */       root.put("domainPackage", domainPackage);
/*     */       
/* 661 */       root.put("feilds", createBean.getBeanFeilds(tableName, className));
/* 662 */       FreemarkerEngine.createFileByFTL(cfg, root, "domainClass.ftl", pathSrc, domainPath);
/*     */     }
/*     */     catch (Exception e) {
/* 665 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */   private static void createEntitySub(String projectName, SubTableEntity subTabParamIn)
/*     */   {
/*     */     try
/*     */     {
/* 673 */       String tableName = subTabParamIn.getTableName();
/* 674 */       String className = subTabParamIn.getEntityName();
/* 675 */       String codeName = subTabParamIn.getFtlDescription();
/* 676 */       String bussiPackage = subTabParamIn.getEntityPackage();
/*     */       
/* 678 */       String basePackage = CodeResourceUtil.getConfigInfo("base_package");
/* 679 */       basePackage = basePackage + "." + projectName;
/* 680 */       if (StringUtils.isNotEmpty(bussiPackage)) {
/* 681 */         basePackage = basePackage + "." + bussiPackage;
/*     */       }
/* 683 */       String domainPackage = basePackage + ".entity";
/* 684 */       String domainPath = domainPackage.replace(".", "\\") + "\\" + className + "Entity.java";
/* 685 */       root.put("className", className);
/* 686 */       root.put("codeName", codeName);
/* 687 */       root.put("tableName", tableName);
/* 688 */       root.put("domainPackage", domainPackage);
/*     */       
/* 690 */       root.put("feilds", createBean.getBeanFeilds(tableName, className));
/* 691 */       FreemarkerEngine.createFileByFTL(cfg, root, "domainClass.ftl", pathSrc, domainPath);
/*     */     }
/*     */     catch (Exception e) {
/* 694 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getProjectPath()
/*     */   {
/* 705 */     String path = System.getProperty("user.dir").replace("\\", "/") + "/";
/* 706 */     return path;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public static String getClassPath()
/*     */   {
/* 714 */     String path = new CodeGenerateFactoryOneToMany().getClass().getResource("/").getPath();
/* 715 */     return path;
/*     */   }
/*     */ }


/* Location:              /Users/guo/.m2/repository/org/jeewxframework/P3-Codegenerate/2.0.1/P3-Codegenerate-2.0.1.jar!/org/jeecgframework/p3/cg/factory/CodeGenerateFactoryOneToMany.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */